#
# File: debug.py
# Description: debug helper
#
# Copyright 2013 Adam Meadows
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

def gaebp():
    '''
    Taken from
    http://eatdev.tumblr.com/post/12076034867/using-pdb-on-app-engine
    '''
    import sys
    pipes = ('stdin', 'stdout', 'stderr');

    # save GAE remapped pipes
    oldpipes = [getattr(sys, pipe) for pipe in pipes]
    for attr in pipes:
        # map pipes back to base
        setattr(sys, attr, getattr(sys, '__%s__' % attr))

    # do breakpoint
    import pdb
    pdb.set_trace()

    # restore GAE remappings
    for i, pipe in enumerate(pipes):
        setattr(sys, pipe, oldpipes[i])
